import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/widgets.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/util/ext_utils.dart';
import 'package:ls_work/viewmodel/hand_over/hand_over_detail_view_model.dart';

import '../../a_yyt/models/handover_new_entity.dart';

class HandOverDetailFragment extends BaseStatefulMvvmWidget {
  HandoverNewInfo info;
  dynamic areaId;

  HandOverDetailFragment({required this.info, required this.areaId});

  @override
  State<StatefulWidget> createState() => _HandOverDetailState();
}

class _HandOverDetailState
    extends BaseMvvmState<HandOverDetailViewModel, HandOverDetailFragment> with AutomaticKeepAliveClientMixin {

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return initProvider();
  }

  @override
  Widget? buildLoadingContentView() {
    var info = viewModel.detailInfo;
    return info == null
        ? Container()
        : Column(
      crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              SizedBox(height: 12,),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  CommonText(info.reportDate
                      ?.changeTime(format: ['yyyy', '-', 'mm', '-', 'dd']),textSize: 18),
                  SizedBox(
                    
                    height: 12,
                  ),
                  CommonText(
                    '本区域入住${info.elderCount ?? ''}位长者，交班涉及${info.relateElderCount ?? ''}位长者，护工${info.nurseCount}人',
                  )
                ],
              ).addToContainer(
                margin: EdgeInsets.symmetric(horizontal: 16),
                width: double.infinity,
                padding: EdgeInsets.symmetric(horizontal: 14,vertical: 14),
                  decoration: BoxDecoration(
                      color: Colours.bg_color, borderRadius: 5.borderRadius)),

              if(!info.summary.isNullOrEmpty())
                ...[
                  SizedBox(height: 30,),
                  CommonText('交班总结',textSize: 18).addToContainer(margin: EdgeInsets.symmetric(horizontal: 16)),
                  SizedBox(height: 25,),
                  Row(
                    children: [
                      CommonText(info.operator??""),
                      SizedBox(width: 20,),
                      CommonText(info.summaryTime)
                    ],
                  ).addToContainer(
                    margin: EdgeInsets.symmetric(horizontal: 16)
                  ),
                  SizedBox(height: 12,),
                  SingleChildScrollView(
                    child: CommonText(info.summary).addToContainer(margin: EdgeInsets.symmetric(horizontal: 16)),
                  ).setWeight(1)
                ],

              

              if(info.archive==0)
              TextButton(onPressed: (){
                viewModel.showHandOverArchiveBottomSheet();
              }, child: CommonText('总结',textColor: Colors.white),
              style: ButtonStyle(
                backgroundColor: WidgetStateProperty.all(Colours.app_main),
                shape: WidgetStateProperty.all(StadiumBorder()),
                minimumSize: WidgetStateProperty.all(Size(double.infinity,49)),
              ),).addToContainer(margin: EdgeInsets.symmetric(horizontal: 16,vertical: 20))
            ],
          );
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return loadingContentWidget;
  }

  @override
  HandOverDetailViewModel createViewModel() {
    return HandOverDetailViewModel(context,
        info: widget.info, areaId: widget.areaId);
  }

  @override
  void onRetryClick() {
    viewModel.requestDetail();
  }

  @override
  bool get wantKeepAlive => true;
}
